package com.yesallchina.wxapp.officialaccount.api.beans;

import com.yesallchina.wxapp.officialaccount.api.enums.MessageEventTypeEnum;
import com.yesallchina.wxapp.officialaccount.utils.JacksonUtils;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.HashMap;
import java.util.Map;

@XmlRootElement(name = "xml")
public class ImageMessage extends Message {

    private String PicUrl;
    private String MediaId;
    private Image Image;

    public ImageMessage(){
        super();
        super.setMsgType(MessageEventTypeEnum.IMAGE.getMsgType());
    }

    public ImageMessage(String mediaId) {
        super();
        super.setMsgType(MessageEventTypeEnum.IMAGE.getMsgType());
        this.Image = new Image();
        this.Image.setMediaId(mediaId);
    }

    @XmlElement(name = "PicUrl")
    public String getPicUrl() {
        return PicUrl;
    }

    public void setPicUrl(String picUrl) {
        PicUrl = picUrl;
    }

    @XmlElement(name = "MediaId")
    public String getMediaId() {
        return MediaId;
    }

    public void setMediaId(String mediaId) {
        MediaId = mediaId;
    }

    @XmlElement(name = "Image")
    public ImageMessage.Image getImage() {
        return Image;
    }

    public void setImage(ImageMessage.Image image) {
        Image = image;
    }

    public static class Image {
        private String MediaId;

        @XmlElement(name = "MediaId")
        public String getMediaId() {
            return MediaId;
        }

        public void setMediaId(String mediaId) {
            MediaId = mediaId;
        }
    }

    @Override
    public String toCustomerMessage() {
        Map<String, Object> msg = new HashMap<>();
        msg.put("touser", getToUserName());
        msg.put("msgtype", MessageEventTypeEnum.IMAGE.getMsgType());
        Map<String, Object> image = new HashMap<>();
        image.put("media_id", getMediaId());
        msg.put("image", image);
        return JacksonUtils.generate(msg);
    }
}